<div id="ban-mobile">
    <div class="center">
        <div style="border: none" class="title">
            <p class="p1">绑定手机号</p>
        </div>
        <div class="bobo">
            <div class="bobo-item">
                <input class="bobo-inp" type="number" maxlength="11" id="band-mobile" placeholder="请输入手机号码" />
            </div>
            <div class="bobo-item">
                <input class="bobo-inp boboleft" type="number" id="band-code" maxlength="6" placeholder="请输入短信验证码" />
                <a href="javascript:void(0);" class="bobo-code">发送短信</a>
            </div>
            <input type="hidden" id="parent-mobile" value="{:input('parent_mobile')}" />
            <a href="javascript:void(0);" class="bobo-btn">确定</a>
        </div>
        <div class="xieyi">绑定代表您已同意<a href="{:url('Info/treaty')}">{$global.system_title}用户协议、隐私政策</a></div>
    </div>
</div>
{php}$pregRule=config('tel_regular');{/php}
<script type="text/javascript">
    $(function () {
        var preg = {$pregRule};
        //发短信
        $(".bobo-code").click(function () {
            if($(".bobo-code").hasClass("disabled")){
                $.Toast('提示','请等待时间刷新后再点击发送！','warning');
                return false;
            }
            var mobile = $("#band-mobile").val();
            if(mobile==''){
                $.Toast('提示','请输入手机号码！','warning');
                return false;
            }
            if(!preg.test(mobile)){
                $.Toast('提示','手机号码有误！','warning');
                return false;
            }
            if($(".bobo-code").hasClass("sending")){
                $.Toast('提示','短信发送中，请稍候！','warning');
                return false;
            }
            $.ajax({
                type:'post',
                url:"{:url('Utils/sendCode')}",
                data:{mobile:mobile},
                cache:false,
                dataType:'JSON',
                success:function(data){
                    $(".bobo-code").removeClass('sending');
                    if(data.status==0){
                        $.Toast('提示',data.info,'success');
                        timeCut(60);
                    }else{
                        $.Toast('提示',data.info,'error');
                    }
                },
                error:function(e){
                    $(".bobo-code").removeClass('sending');
                },
                beforeSend:function(e){
                    $(".bobo-code").addClass('sending');
                }
            });
        });

        //提交
        $(".bobo-btn").click(function () {
            var mobile = $("#band-mobile").val();
            var code = $("#band-code").val();
            var parent_mobile = $("#parent-mobile").val();
            if(mobile==''){
                $.Toast('提示','请输入手机号码！','warning');
                return false;
            }
            if(!preg.test(mobile)){
                $.Toast('提示','手机号码有误！','warning');
                return false;
            }
            if(code==''){
                $.Toast('提示','请输入短信验证码！','warning');
                return false;
            }
            if($(".bobo-btn").hasClass("sending")){
                $.Toast('提示','绑定提交中，请稍候！','warning');
                return false;
            }
            $.ajax({
                type:'post',
                url:"{:url('Utils/band')}",
                data:{mobile:mobile,code:code,parent_mobile:parent_mobile},
                cache:false,
                dataType:'JSON',
                success:function(data){
                    $(".bobo-btn").removeClass('sending');
                    if(data.status==0){
                        $.Toast('提示',data.info,'success');
                        setTimeout(function () {
                            window.location.reload();
                        },2000)
                    }else{
                        $.Toast('提示',data.info,'error');
                    }
                },
                error:function(e){
                    $(".bobo-btn").removeClass('sending');
                },
                beforeSend:function(e){
                    $(".bobo-btn").addClass('sending');
                }
            });
        });
        function timeCut(count) {
            var countDown = setInterval(function () {
                if (count <= 0) {
                    $('.bobo-code').text('重新发送').removeClass('disabled').css('color','#FF4546');
                    clearInterval(countDown);
                } else {
                    $('.bobo-code').addClass('disabled').css('color','#BFBFBF');
                    $('.bobo-code').text(count+'秒');
                }
                count--;
            }, 1000);
        }
    });
</script>